<?php
session_start();
function RandStr($length)
{
	$char = "abcdefghijlmnuiprtsgqwxyz123456789";
	
	$size = strlen($char);
	for($i = 0; $i<$length; $i++)
	{
		$str .= $char[rand(0, $size-1)];
	}
	
	return $str;
}

?>
<?php

$ResultStr = RandStr(6);

$NewImage =imagecreatefromjpeg("img.jpg");//image create by existing image and as back ground 


$TextColor = imagecolorallocate($NewImage, 255, 255, 255);//text color-white

imagestring($NewImage, 5, 10,5, $ResultStr, $TextColor);// Draw a random string horizontally 


$_SESSION['key'] = $ResultStr;// carry the data through session

header("Content-type: image/jpeg");// out out the image 

imagejpeg($NewImage);//Output image to browser

?>
